iT邦幫忙

2022 iThome 鐵人賽

DAY 26
0
Web 3

當 APP develop 遇上 web3 與 Metaverse 浪潮 系列 第 26

[Day 貳拾陸] 來開發元宇宙中藥鋪吧14 - 中藥包NFT???

  • 分享至 

  • xImage
  •  

既然是元宇宙中藥鋪,中藥當然也是以 NFT 的方式販售啊XD

我們這次選擇的鏈為 polygon 使用 (MATIC 代幣)
polygon 測試網為 (Mumbai)

MetaData 與素材檔案將利用 NFT.Storage 存放在 (IPFS) 上

https://wiki.polygon.technology/docs/develop/nftstorage/#creating-your-nft-on-polygon

https://ipfs.io/ipfs/bafkreidynrzkx2rymz257xosvtortuwt5uwcvtergf4lpdbe3f2yudzfia

OpenSea MetaData Example

{
    "image": "ipfs://bafkreiet7k6btmxuwwzu7spig4pci45upj2444htkhfjawll43bvmykoaq",
    "animation_url": "ipfs://bafkreihsrqpj3sywirldse3k4age6gkfgp2os4cxtkphree32s37u7n5ou?filename=animation.gltf",
    "schem": "ipfs://bafkreia4ph2osgfkhpzgqxa6teq7ygifbddf7f4qx3mzmfyujnj7h5utei",
    "name": "Creativerse Plot #4900",
    "description": "This is plot #4900 located in the Creativerse as (49, 49).",
    "attributes": [
        {
            "display_type": "date",
            "value": "1645680146490",
            "trait_type": "Last Saved"
        },
        {
            "display_type": "number",
            "value": 49,
            "trait_type": "Plot X"
        },
        {
            "display_type": "number",
            "value": 49,
            "trait_type": "Plot Z"
        }
    ]
}

store-asset.mjs

import { NFTStorage, File } from "nft.storage"
import fs from 'fs'
import dotenv from 'dotenv'
dotenv.config()

const { NFT_STORAGE_API_KEY } = process.env

async function storeAsset() {
   const client = new NFTStorage({ token: NFT_STORAGE_API_KEY })
   const metadata = await client.store({
       name: 'ExampleNFT',
       description: 'My ExampleNFT is an awesome artwork!',
      image: new File(
        [await fs.promises.readFile('assets/中藥包0001-0200.gif')],
        'preview.gif',
        { type: 'image/gif' }
    ),
       
       animation_url: new File(
        [await fs.promises.readFile('assets/中藥包.gltf')],
        'model.gltf',
        { type: 'model/gltf+json' }
    ),
    name: "元宇宙中醫館 中藥包 #4900",
    description: "This is 中藥包 #4900 located in the Creativerse as 元宇宙中醫館",
    attributes: [
        {
            "display_type": "date",
            "value": "1645680146490",
            "trait_type": "Last Saved"
        },
        {
            "display_type": "string",
            "value": '元宇宙中醫館',
            "trait_type": "中醫館"
        },
        {
            "display_type": "number",
            "value": 49,
            "trait_type": "中藥包"
        }
    ]
   })
   console.log("Metadata stored on Filecoin and IPFS with URL:", metadata.url)
}

storeAsset()
   .then(() => process.exit(0))
   .catch((error) => {
       console.error(error);
       process.exit(1);
   });

按照教學部署後 mint 即可


上一篇
[Day 貳拾五] 來開發元宇宙中藥鋪吧14 - 建立測試空間
下一篇
[Day 貳拾柒] 來開發元宇宙中藥鋪吧15 - 中藥包NFT?丟進去場景吧
系列文
當 APP develop 遇上 web3 與 Metaverse 浪潮 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言